package com.lhsy.djcloud.controller;

import com.google.common.collect.Maps;
import com.lhsy.djcloud.common.ReturnT;
import com.lhsy.djcloud.entity.NoticeMessage;
import com.lhsy.djcloud.entity.dto.UserDto;
import com.lhsy.djcloud.service.NoticeMessageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * @author kate
 */
@RestController
@RequestMapping("/index")
@Api(value = "Server-API",tags = "首页数据获取")
public class IndexController extends BaseController{
    @Autowired private NoticeMessageService noticeMessageService;

    @ApiOperation(value = "获取当前用户的所有未读消息数量")
    @RequestMapping(value = "/message/unreadNum",method = RequestMethod.GET)
    public ReturnT<Map<String,Integer>> getUnReadNum(HttpServletRequest request){
        UserDto currUser = getCurrUser(request);
        //获取当前用户的未读消息
        List<NoticeMessage> ggMessages1 = noticeMessageService.selectUnReadMessage(currUser.getUserId(),1);
        List<NoticeMessage> ggMessages2 = noticeMessageService.selectUnReadMessage(currUser.getUserId(),2);
        List<NoticeMessage> ggMessages3 = noticeMessageService.selectUnReadMessage(currUser.getUserId(),3);
        Map<String,Integer> params = Maps.newHashMap();
        params.put("1",ggMessages1.size());
        params.put("2",ggMessages2.size());
        params.put("3",ggMessages3.size());
        return ReturnT.SUCCESS(params);

    }

    @ApiOperation(value = "获取当前用户的未读 任务/简报/消息/未读公告")
    @RequestMapping(value = "/message/unreadNotice",method = RequestMethod.GET)
    public ReturnT<List<NoticeMessage>> getUnReadNotice(HttpServletRequest request){
        UserDto currUser = getCurrUser(request);
        List<NoticeMessage>  ggMessages = noticeMessageService.selectUnReadMessage(currUser.getUserId(),1);
        List<NoticeMessage>  jbMessages = noticeMessageService.selectUnReadMessage(currUser.getUserId(),2);
        List<NoticeMessage>  messages = noticeMessageService.selectUnReadMessage(currUser.getUserId(),3);
        Map<String, List<NoticeMessage>> resultMap = Maps.newHashMap();
        //未读消息
        resultMap.put("1",ggMessages);
        //未读简报
        resultMap.put("2",jbMessages);
        resultMap.put("3",messages);
        return ReturnT.SUCCESS(resultMap);
    }

}
